﻿using CloudFranceTriple.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace CloudFranceTriple.Tests.Areas.Forum
{
    [TestClass]
    public class CategoryControllerTest : UnitTestBase
    {
        [TestMethod]
        [TestCategory("Forum.Category")]
        public void CategoryController_Create_Get()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.CategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Create(UnitTestCategory_ForumId) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Forum.Category")]
        public void CategoryController_Create_Post_ModelIsValid()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.CategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            var _now = DateTime.UtcNow;
            var categoryset = new ForumCategorySet
            {
                Forum_Id = UnitTestCategory_ForumId,
                LabelForumCategory = "Category - UnitTest",
                LastPostAuthor = "UnitTest",
                LastPostCreationDate = DateTime.UtcNow,
                LastPostId = 0,
                LastPostTopicId = 0,
                NumberOfMessage = 0,
                NumberOfTopic = 0,
                OrderForumCategory = 0,
                DescriptionForumCategory = "Unit Test - Description"
            };

            // Act
            var result = controller.Create(categoryset) as RedirectToRouteResult;


            UnitTestCategoryId = categoryset.Id;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Forum.Category")]
        public void CategoryController_MoveUp()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.CategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.MoveUp(UnitTestCategoryId) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Forum.Category")]
        public void CategoryController_MoveDown()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.CategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.MoveDown(UnitTestCategoryId) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Forum.Category")]
        public void CategoryController__Edit_Get()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.CategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Edit(UnitTestCategoryId) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Forum.Category")]
        public void CategoryController__Edit_Post()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.CategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            var _now = DateTime.UtcNow;
            var categoryset = new ForumCategorySet
            {
                Id = UnitTestCategoryId,
                Forum_Id = UnitTestCategory_ForumId,
                LabelForumCategory = "Category - UnitTest",
                LastPostAuthor = "UnitTest",
                LastPostCreationDate = DateTime.UtcNow,
                LastPostId = 0,
                LastPostTopicId = 0,
                NumberOfMessage = 0,
                NumberOfTopic = 0,
                OrderForumCategory = 10,
                DescriptionForumCategory = "Unit Test - Description"
            };

            // Act
            var result = controller.Edit(categoryset) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Forum.Category")]
        public void CategoryController_Delete_Get()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.CategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.Delete(UnitTestCategoryId) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        [TestCategory("Forum.Category")]
        public void CategoryController_DeleteConfirmed_Post()
        {
            // Arrange
            var controller = new CloudFranceTriple.WebRole.Areas.Forum.Controllers.CategoryController();

            controller.ControllerContext = base.GetControllerContext.Object;

            var context =
                new Mock<HttpContextBase>(MockBehavior.Strict);

            controller.Url =
                new UrlHelper(new RequestContext(context.Object,
                new RouteData()), new RouteCollection());

            // Act
            var result = controller.DeleteConfirmed(UnitTestCategoryId) as RedirectToRouteResult;

            // Assert
            Assert.IsNotNull(result);
        }
    }
}
